package com.axun.qqcountdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TextView mTvChange;
    private ListView mLvList;

    private UserManageAdapter mAdapter;
    private boolean change = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mTvChange = (TextView) findViewById(R.id.tv_change);
        mLvList = (ListView) findViewById(R.id.lv_list);
        mAdapter = new UserManageAdapter(this);
        mLvList.setAdapter(mAdapter);
        initData();
        mTvChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (change){
                    mAdapter.setChange(false);
                    change = false;
                }else {
                    mAdapter.setChange(true);
                    change = true;
                }
            }
        });

       mAdapter.setOnUserManageListener(new UserManageAdapter.OnUserManageListener() {
           @Override
           public void onItemClick(View view, int position) {
               mAdapter.setSelection(position);
           }

           @Override
           public void onDeleteIconClick(View view, int position) {
               mAdapter.setShowDelete(position);
           }

           @Override
           public void onDeleteClick(View view, int position) {

           }
       });
    }

    private void initData(){
        List<UserSavedModule> items = new ArrayList<>();
        items.add(new UserSavedModule("18869978285","六娃","123456"));
        items.add(new UserSavedModule("13456655479","czz","123456"));
        items.add(new UserSavedModule("13456655479","czz","123456"));
        mAdapter.setItems(items);
    }
}
